import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const state = {
	token: '',
	userInfo: {
		username: '',
		phone: '',
	},
	userLevelStatus: 1,   //会员状态
	orderStatus : 1 ,   //订单状态
	resource: '',
}

const mutations = {
	LOGIN_SUCCESS(state, data) {
		state.token = data.token
		state.userInfo.username = data.username
		state.userInfo.phone = data.phone
	},
	LOGIN_OUT(state) {
		state.token = ''
		state.userInfo.username = ''
		state.userInfo.phone = ''
	},
	GET_RESOURCE(state, resource) {
		state.resource = resource;
	},
	GET_LEVEL(state,userLevelStatus) {
		state.userLevelStatus = userLevelStatus
	}
}

const actions = {
	actionLoginSuccess({ commit }, user) {
		commit('LOGIN_SUCCESS', user)
	},
	actionLoginOut({ commit }) {
		commit('LOGIN_OUT')
	}
}

const store = new Vuex.Store({
	state,
	mutations,
	actions
})

export default store